<%@page import="dao.EmployeeDao"%>
<%@include file="template/configuration.jsp" %>
<%@page import="models.Employee"%>
<%@page import="java.util.List"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || ${uq_manage_teachers}</title>
        ${stylesheet}
        ${jquery}
        ${jsdropdown}
        ${jstooltip}
        ${jspagination}
    </head>
    <body>
        <div class="container">
            <%@include file="template/header.jsp" %>
            <div class="content">
                <h1>${uq_manage_teachers}</h1>
                <div class="third-block no-height">
                    <a href="ManageTeacher">${uq_add_a_new_teacher} <img src="${url}images/add.png" class="icon-text" border="0" /></a>
                </div>
                <div class="search-block no-height float-right">
                    <label for="search">${uq_search}</label> <input type="text" name="search" id="search" value=""/>
                </div>
                <div class="clear margin-bottom-10"></div>
                <div class="full-block">
                    <c:choose>
                        <c:when test="${employees!=null}">
                            <table class="overview" id="search-table">
                                <thead>
                                <tr>
                                    <th class="single-icon"></th>
                                    <th>${uq_full_name}</th>
                                    <th>${uq_description}</th>
                                    <th>${uq_email}</th>
                                    <th>${uq_courses}</th>
                                    <th class="date">${uq_added}</th>
                                    <th class="manage">${uq_manage}</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:set var="i" value="0"/>
                                <c:forEach items="${employees}" var="employees">
                                    <c:set var="i" value="${i + 1}"/>
                                    <tr class="<c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                        <td><c:if test="${employees.role.name eq 'Administrator'}"><img src="${url}images/admin.png"/></c:if></td>
                                        <td><a href="">${employees.firstname} ${employees.insertion} ${employees.lastname}</a></td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${fn:length(employees.description) > 40}">
                                                     <c:out value="${fn:substring(employees.description, 0, 40)}"/>...
                                                </c:when>
                                                <c:otherwise>
                                                    ${employees.description}
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>${employees.user.email}</td>
                                        <td>
                                            <img src="${url}images/question.png" class="question" />
                                            <div class="relative">
                                                <div class="tooltip">
                                                    <c:forEach items="${courses}" var="courses">
                                                        <c:forEach items="${courses.teacher}" var="courseteacher">
                                                            <c:choose>
                                                                <c:when test="${courseteacher.id==employees.id}">${courses.name}</br></c:when>
                                                            </c:choose>
                                                        </c:forEach>
                                                    </c:forEach>
                                                </div>
                                            </div>
                                        </td>
                                        <td>${employees.user.date}</td>
                                        <td><a href="${url}Teacher/edit?id=${employees.id}"><img src="${url}images/edit.png"/></a> 
                                            <c:if test="${employees.removable}">
                                                <a href="${url}Teacher/remove?idremove=${employees.id}" class="remove"><img src="${url}images/remove.png"/></a>
                                                <span class="info">teacher <strong>${employees.firstname} ${employees.insertion} ${employees.lastname}</strong></span>
                                            </c:if>                                            
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                            <%
                            HibernateUtil humt = new HibernateUtil();
                            EmployeeDao cdmt = new EmployeeDao(humt.openSession());
                            double total_items = cdmt.getLastPage();
                            pageContext.setAttribute("pagination", (int) Math.ceil(total_items / 15));
                            %>
                            <c:if test="${pagination > 1}">
                                <div class="pagination">
                                    <c:forEach var="i" begin="1" end="${pagination}" step="1">
                                        <a href="${url}jsp/pagination/manage_teachers.jsp?page=${i}" class="number<c:if test="${i == '1'}"> active</c:if>">${i}</a>
                                    </c:forEach>
                                </div>
                            </c:if>
                        </c:when>
                        <c:otherwise>
                            <div class="no-yet-message">
                                There are no teachers at this moment yet.
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
            <%@include file="template/footer.jsp" %>
        </div>
    </body>
</html>
